<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>后台登录</title>
  <link rel="stylesheet" href="__STATIC__/css/font.css">
	<link rel="stylesheet" href="__STATIC__/css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
</head>
<body class="login-bg">
    
    <div class="login layui-anim layui-anim-up">
        <div class="message">Admin-管理登录</div>
        <div id="darkbannerwrap"></div>
        <input id="username" placeholder="用户名"  type="text" class="layui-input" >
        <hr class="hr15">
        <input id="password" placeholder="密码"  type="password" class="layui-input">
        <hr class="hr15">
        <input type="text" id="verifycode" placeholder="验证码" class="layui-input" style="display:inline-block;vertical-align:middle;width:190px;">
        <img src="{:captcha_src()}" id="img" onclick="reloadImg()" style="float:right;vertical-align:middle;">
        <hr class="hr15">
        <button class="layui-btn" onclick="dologin()" style="width:100%;">登录</button>
        <hr class="hr20">
    </div>
<script type="text/javascript">
    layui.use(['layer'],function(){
      $ = layui.jquery;
      layer = layui.layer;


      // 用户名控件获取焦点
      $('#username').focus();
      // 回车登录
      $('input').keydown(function(e){
        if(e.keyCode == 13){
          dologin();
        }
      });
    });

    // 重新生成验证码
    function reloadImg(){
      $('#img').attr('src','{:captcha_src()}?rand='+Math.random());
    }
    // 登录
    function dologin(){
      var username = $.trim($('#username').val());
      var pwd = $.trim($('#password').val());
      var verifycode = $.trim($('#verifycode').val());
      if(username == ''){
        layer.alert('请输入用户名',{icon:2});
        return;
      }
      if(pwd == ''){
        layer.alert('请输入密码',{icon:2});
        return;
      }
      if(verifycode==''){
        layer.alert('请输入验证码',{icon:2});
        return;
      }
      $.post('{:url("login/dologin")}',{'username':username,'pwd':pwd,'verifycode':verifycode},function(res){
        if(res.code>0){
          reloadImg();
          layer.alert(res.msg,{icon:2});
        }else{
          layer.msg(res.msg,{icon:6});
          setTimeout(function(){window.location.href = '/admin.php'},1000);
        }
      },'json');
    }
</script>
</body>
</html>